const { default: commonjs } = require("@rollup/plugin-commonjs");
const { default: nodeResolve } = require("@rollup/plugin-node-resolve");
const { babel } = require("@rollup/plugin-babel");
const { default: terser } = require("@rollup/plugin-terser");

module.exports = {
  input: "./lib/index.js",
  output: [
    {
      format: "umd",
      name: "whyUtils",
      file: "./build/bundle.umd.js",
      globals: {
        lodash: "_",
      },
    },
    {
      format: "amd",
      file: "./build/bundle.amd.js",
      globals: {
        lodash: "_",
      },
    },
    {
      format: "cjs",
      file: "./build/bundle.cjs.js",
      globals: {
        lodash: "_",
      },
    },
    {
      format: "iife",
      name: "whyUtils",
      file: "./build/bundle.browser.js",
      globals: {
        lodash: "_",
      },
    },
  ],
  external: ["lodash"],
  plugins: [
    commonjs(), // 默认loadsh没有打包时因为使用commonjs，rollup默认情况下只会处理es module
    nodeResolve(),
    babel({
      babelHelpers: "bundled",
      exclude: /node_modules/,
    }),
    terser(),
  ],
};
